package homevideo_model

import (
	"encoding/json"
	"fmt"
	"iptv_server/v3/src/database"
	"iptv_server/v3/src/mydebug"
	"testing"
)

func TestPlay_Create(t *testing.T) {
	mydebug.InitDB()

	database.DB.AutoMigrate(new(Play))
	urls := []string{
		"http://server.lan:9966/videos/12_tv2/%E8%B4%9E%E8%A7%82%E4%B9%8B%E6%B2%BB%202006/E24.mkv",
		"http://server.lan:9966/videos/12_tv2/%E7%AC%AC8%E5%8F%B7%E5%BD%93%E9%93%BA%282003%29/%E7%AC%AC%E5%85%AB%E5%8F%B7%E5%BD%93%E9%93%BA%282003%29S01E018.mkv",
	}
	names := []string{
		"name1",
		"name2",
		"",
	}
	for dtId := 1; dtId < 10; dtId++ {
		for i := 0; i < 15; i++ {
			p := &Play{
				DetailID: uint(dtId),
				Url:      urls[i%len(urls)],
				Name:     names[i%len(names)],
				// PlayerArgs: tt.fields.PlayerArgs,
			}
			if err := p.Create(); err != nil {
				t.Errorf("Play.Create() error = %v", err)
			}
		}
	}
}

func TestGetPlay(t *testing.T) {
	mydebug.InitDB()

	gotP, err := GetPlay(1)

	fmt.Printf("gotP: %v\n", gotP)
	fmt.Printf("err: %v\n", err)
	jo, err := json.Marshal(gotP)
	fmt.Printf("jo: %v\n", jo)
	fmt.Printf("err: %v\n", err)

}
